package com.nwpu.am.config;

import com.nwpu.am.constant.SwaggerConstant;
import com.nwpu.am.constant.properties.SwaggerProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;

/**
 * SwaggerConfig
 *
 * @author Roy
 * @version 1.0
 * {@code @date} 2024/6/3
 */

@Configuration
@Slf4j
public class SwaggerConfig {
    @Resource
    private SwaggerProperties swaggerProperties;

    public SwaggerConfig() {
        log.info("准备生成接口文档。。。");
    }

    @Bean
    public Docket docket() {
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(swaggerProperties.getTitle())
                .version(swaggerProperties.getVersion())
                .description(swaggerProperties.getDescription())
                .build();
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(SwaggerConstant.GROUP_NAME)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage(SwaggerConstant.BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }
}
